#ifndef SLAVETASKRANDOM
#define SLAVETASKRANDOM

#include <AbstractGridSlaveTask.h>
#include <boost/enable_shared_from_this.hpp>
#include <boost/shared_ptr.hpp>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

using namespace MasterWorkerFramework;

class GridSlaveTaskRandomNumber : public AbstractGridSlaveTask,public boost::enable_shared_from_this<GridSlaveTaskRandomNumber>
{

public:
	GridSlaveTaskRandomNumber (char* name)
		:AbstractGridSlaveTask(name){

			slave_task_name_= new std::string("GridSlaveTaskRandomNumber");
	}

	std::string* GetSlaveTaskName()
	{
		return slave_task_name_;
	}

	 VALUE_TYPE GetTaskType()
	{
		return VALUE_TYPE::VALUE_TYPE_FLOAT;
	}

	void Execute()
	{
			float*ptr;
			float value=0;

		for (std::vector<TaskResult*>::iterator vi = bindedResults_->begin(); vi != bindedResults_->end(); vi++)
			{
				if ((*vi)->GetType()==VALUE_TYPE::VALUE_TYPE_FLOAT)
				{
					value+= *((*vi)->GetResult<float>());
				}

				else if ((*vi)->GetType()==VALUE_TYPE::VALUE_TYPE_INT32)
				{
					value+= *((*vi)->GetResult<int>());
				}
			}

		for (int i = 0; i< iteration_;i++)
		{
			srand(time(NULL));
			Sleep(100);

			for (int i =0; i< 100; i++)
			{	
				value+=rand();
			}

		}

		result_ =  new TaskResult(VALUE_TYPE::VALUE_TYPE_FLOAT);
		
		ptr= new float(value);
		result_->SetResult<float>(ptr);
	}

	~GridSlaveTaskRandomNumber()
	{
		delete slave_task_name_;
	}

private:
	std::string* slave_task_name_;
};

#endif